<?php
    class Diskon_con extends CI_Controller{
        function __construct() {
            parent::__construct();
        }
        function index(){
            $this->list_diskon();
        }
        function list_diskon(){
            $query=$this->db->get('diskon');
            $this->load->library('table');
            $this->table->set_template(array('table_open' => '<table align="center" width="50%" border="1" cellpadding="4" cellspacing="3">'));
            $this->table->set_heading('NO', 'NAMA DISKON', 'BESAR', 'AKSI');
            $i=1;
            if($query->num_rows()>0){
                foreach($query->result() as $entry){
                    $this->table->add_row(
                    $i,
                    $entry->NAMA_DISKON,
                    $entry->BESAR,
                    anchor(base_url().'admin/diskon_con/delete/'.$entry->ID_DISKON,'Delete')        
                    );
                    $i++;
                }
                $display['content']=$this->table->generate();
            }else{
                $display['content']='Belum ada diskon yang dibuat';
            }
            $data['title']="List Diskon";
            $this->load->view('admin/admin_header_view', $data);
            $this->load->view('admin/diskon_view', $display);
            $this->load->view('footer_view');
        }
        function insert(){
            $this->db->insert('diskon',$_POST);
            redirect(base_url().'admin/diskon_con');
        }
        function delete($id){
            $this->db->delete('diskon',array('ID_DISKON'=>$id));
            redirect(base_url().'admin/diskon_con');
        }
    }
?>
